<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>AUI快速完成布局</title>
    <!--标准mui.css-->

    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
</head>
<style type="text/css">
    .aui-list-item.wechat-top {
        background-color: #f3f3f7;
    }
    .aui-list .wechat-avatar {
        width:3rem;
    }
    .wechat-avatar .aui-row-padded {
        background-color: #dddee0;
        padding: 0.1rem;
        border-radius: 0.2rem;
        margin-left: -0.05rem;
        margin-right: -0.05rem;
    }
    .wechat-avatar .aui-row-padded [class*=aui-col-xs-] {
        padding: 0.05rem;
    }
    .wechat-avatar,
    .wechat-avatar > img {
        border-radius:0.2rem;
    }
</style>
<body>
    <section class="aui-content">
      <!--<div class="aui-searchbar" id="search">
          <div class="aui-searchbar-input aui-border-radius">
              <i class="aui-iconfont aui-icon-search"></i>
              <input type="search" readonly="readonly" onclick="openSearchWin()" placeholder="请输入搜索内容" id="search-input">
              <div class="aui-searchbar-clear-btn">
                  <i class="aui-iconfont aui-icon-close"></i>
              </div>
          </div>
          <div class="aui-searchbar-btn" tapmode>取消</div>
      </div>-->
      <ul class="aui-list aui-media-list aui-margin-b-10 aui-margin-t-10">
          <li class="aui-list-item aui-list-item-middle" onclick="openGroupWin();">
                <div class="aui-media-list-item-inner">
                    <div class="aui-list-item-media wechat-avatar">
                        <!--<div class="aui-badge">9</div>-->
                        <img src="../image/users.png" />
                    </div>
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-text">
                            <div class="aui-list-item-title">群组</div>
                        </div>
                    </div>
                </div>
            </li>
      </ul>
      <ul class="aui-list aui-media-list" id="users-list">

      </ul>
    </section>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="../script/aui-toast.js" ></script>
<script type="text/javascript" src="../script/mui/mui.min.js"></script>
<script type="text/javascript">
var toast = new auiToast();
apiready = function(){
     $api.setStorage("mail_index", 0);
     load();
     //上拉翻页
     api.addEventListener({
         name : 'scrolltobottom'
     }, function(ret, err) {
         $api.setStorage("mail_index", $api.getStorage("mail_index") - 0 + 1);
         load();
     });

     //下拉刷新
     api.setRefreshHeaderInfo({
         visible: true,
         loadingImg: 'widget://image/refresh.png',
         bgColor: '#ccc',
         textColor: '#fff',
         textDown: '下拉刷新...',
         textUp: '松开刷新...',
         showTime: true
     }, function(ret, err){
         window.location.reload();
         api.refreshHeaderLoadDone();
     });

     //监听列表刷新
     api.addEventListener({
         name:'userInfoReload'
     },function(ret){
         window.location.reload();
     });
 }

//资讯列表加载
 function load(first, index2) {
     api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '拼命加载中...',
        text: '不如喝茶去...',
        modal: false
     });
     var index = $api.getStorage("mail_index");
     var url = ServeUrl + "m=Daily&a=userInfo&pageIndex=" + index + "&pageCount=15";
     ajaxRequest(url, 'get', '', function(data) {
         dealWithHtml(data, first, index);
     });

 }

 function ajaxRequest(url, method, datas, callBack) {
     api.ajax({
         url : url,
         method : method,
         cache : false,
         timeout : 30,
         dataType : 'json',
         data : {
             values : datas
         }
     }, function(ret, err) {
         if (ret.data) {
             callBack(ret, err);
         } else {
             //alert("没有更多的用户！");
             toast.success({
                 title:"已加载所有用户",
                 duration:2000
             });
             api.hideProgress();
         }
     });
 }

//字符串拼接
 function dealWithHtml(data, first, index) {
    //alert(JSON.stringify(data));
     var html = '';
     for (var i = 0; i < data.data.length; i++) {
       if(data.data[i].user_img){
           var user_img = ''+ServeIp+'include/data/headImg/'+data.data[i].user_img;
       }else {
           var user_img = '../image/user.png';
       }
        html+='<li class="aui-list-item aui-list-item-middle" onclick="openWin('+"'"+data.data[i].user_img+"','"+data.data[i].username+"','"+data.data[i].ryId+"','"+data.data[i].cn_name+"','"+data.data[i].r_name+"','"+data.data[i].d_name+"',"+data.data[i].phone+');">'
        html+='<div class="aui-media-list-item-inner">'
        html+='<div class="aui-list-item-media wechat-avatar">'
        html+='<img src="'+user_img+'" />'
        html+='</div>'
        html+='<div class="aui-list-item-inner">'
        html+='<div class="aui-list-item-text">'
        html+='<div class="aui-list-item-title">'+data.data[i].cn_name+'</div>'
        html+='<div class="aui-list-item-right">'+data.data[i].r_name+'</div>'
        html+='</div>'
        html+='<div class="aui-list-item-text aui-font-size-12">['+data.data[i].username+']</div>'
        html+='</div>'
        html+='</div>'
        html+='</li>';
     }
    $("#users-list").append(html);
    api.hideProgress();
 }

    function openWin(user_img,username,ryId,cn_name,r_name,d_name,phone) {
        api.openWin({
            name: "personal_info",
            url: 'personal_info_win.html',
            pageParam: {
                user_img:user_img,
                username: username,
                ryId:ryId,
                cn_name: cn_name,
                r_name: r_name,
                d_name: d_name,
                phone: phone,
            }
        });
    }

    function openSearchWin(){
        api.openWin({
            name: "search_win",
            url: 'search_win.html',

        });
    }

    function openGroupWin(){
        api.openWin({
            name: "group_chat",
            url: 'group_chat_win.html',

        });
    }
</script>

</html>
